import { createRouter, createWebHistory } from 'vue-router';
import Login from '../components/LoginPage.vue';
import UploadFile from '../components/UploadFilePage.vue';
import Home from '../components/HomePage.vue';
import Logistics from '../components/LogisticsPage.vue';
import UserManager from '../components/UserManager.vue';
import PDFUploadFile from '../components/PDFUpload.vue';

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  { path: '/home', 
    component: Home,  
    children: [
      { path: '/upload', component: UploadFile },
      { path: '/pdfUpload', component: PDFUploadFile },
      { path: '/logistics', component: Logistics  },
      { path: '/userManager', component: UserManager  },
    ], 
    meta: { requiresAuth: true }  },
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

// router.beforeEach((to, from, next) => {
//   const isAuthenticated = checkIsAuthenticated(); // 检查用户是否已经登录

//   if (to.matched.some(record => record.meta.requiresAuth) && !isAuthenticated) {
//     next('/login'); // 如果需要登录权限且未登录，则跳转到登录页面
//   } else {
//     next(); // 允许进入路由
//   }
// });

export default router;